<?php


class mySQL {
    private $Database;
    private $User;
    private $Pwd;
    private $Server;
    private $connection;
    private $resource;
    
    var $lastquery;
      
    function __construct(){        
        $this->Database="bonitosp_bonitos_pecados";
        $this->User="root";
        $this->Pwd="root";
        $this->Server="localhost";
        $this->connection="";
    }
    
    public function connect(){

        @$this->connection=mysql_connect($this->Server,$this->User,$this->Pwd);
        if ($this->connection){
            mysql_select_db($this->Database,$this->connection);
            return true;
        }else{
            return false;
        }
    }

    public function close(){
        return mysql_close($this->connection);
    }   
    
    public function query($query){
        if($this->connection){
            $this->lastquery=$query;
            $this->resource = mysql_query($query, $this->connection);
            if ($this->resource){
                return $this->resource;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }   
    
    public function fetch_assoc($result = null){
        return mysql_fetch_assoc(($result));
    }

    public function fetch_array($result = null){
        return mysql_fetch_array($result);
    }

    public function fetch_row($result = null){
        return mysql_fetch_row($result);
    }

    public function fetch_object($result = null){
        return mysql_fetch_object($result);
    }

    public function num_rows($result = null){
        return @mysql_num_rows($result);
    }

    public function errno($result = null){
        return mysql_errno($result);
    }

    public function error($result = null){
        return mysql_error($result);
    }
      
    public function begin_transaction(){
        if($this->query("BEGIN")){
            return true;
        }else{
            return false;
        }
    }
    
    public function commit_transaction(){
        if($this->query("COMMIT")){
            return true;
        }else{
            return false;
        }
    }
    
    public function rollback_transaction(){
        if($this->query("ROLLBACK")){
            return true;
        }else{
            return false;
        }
    }

    public static function escape_string($string) {
        return mysql_escape_string($string);
    }
    
  }  
?>
